package com.buaa.aimall.userModule.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.buaa.aimall.Utils.Enum.WorkOrderStatusEnum;
import com.buaa.aimall.Utils.PageReturnResult;
import com.buaa.aimall.userModule.DTO.FilterWithdrawalWorkOrderDTO;
import com.buaa.aimall.userModule.DTO.PageDTO;
import com.buaa.aimall.userModule.Entity.RechargePayOrderEntity;
import com.buaa.aimall.userModule.Entity.WithdrawalWorkOrderEntity;
import com.buaa.aimall.userModule.Mapper.WithdrawalWorkOrderMapper;
import org.springframework.stereotype.Service;

@Service
public class WithdrawalWorkOrderServiceImpl extends ServiceImpl<WithdrawalWorkOrderMapper, WithdrawalWorkOrderEntity> implements WithdrawalWorkOrderService {
    public WithdrawalWorkOrderEntity getByMchOrderNo(String mchOrderNo) {
        LambdaQueryWrapper<WithdrawalWorkOrderEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WithdrawalWorkOrderEntity::getMchOrderNo, mchOrderNo);
        return this.getOne(queryWrapper);
    }

    public PageReturnResult<WithdrawalWorkOrderEntity> filterWithdrawalWorkOrder(FilterWithdrawalWorkOrderDTO filterWithdrawalWorkOrderDTO) {
        int pageSize = filterWithdrawalWorkOrderDTO.getPageSize();
        int currentPage = filterWithdrawalWorkOrderDTO.getCurrentPage();
        WorkOrderStatusEnum status = filterWithdrawalWorkOrderDTO.getStatus();

        LambdaQueryWrapper<WithdrawalWorkOrderEntity> queryWrapper = new LambdaQueryWrapper<>();
        if (status != null) {
            queryWrapper.eq(WithdrawalWorkOrderEntity::getStatus, status);
        }

        PageReturnResult<WithdrawalWorkOrderEntity> result = new PageReturnResult<>();
        result.setTotalCount(this.count(queryWrapper));

        result.setRecords(this.page(new Page<WithdrawalWorkOrderEntity>(currentPage, pageSize), queryWrapper).getRecords());
        return result;
    }
}
